<?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE sqlMap PUBLIC "-//ibatis.apache.org//DTD SQL Map 2.0//EN" "http://ibatis.apache.org/dtd/sql-map-2.dtd" >
<sqlMap namespace="com.uc.training.smadmin.gds.dao.GoodsPicDao">

    <select id="getPropertyIdById" parameterClass="Long" resultClass="Long">
      select property_id
      from t_gds_goods_pic
      where id = #id#
    </select>

    <!--新增商品属性-->
    <insert id="insertGoodsPic" parameterClass="com.uc.training.smadmin.gds.model.GoodsPic">
        INSERT INTO t_gds_goods_pic
        (property_id, pic_name, pic_url, create_emp, modify_emp)
        VALUES (#propertyId#,#picName#,#picUrl#,#createEmp#,#modifyEmp#)
        <selectKey resultClass="long" keyProperty="id">
            SELECT LAST_INSERT_ID() as id;
        </selectKey>
    </insert>

    <!--更新商品属性-->
    <update id="updateGoodsPic" parameterClass="com.uc.training.smadmin.gds.model.GoodsPic">
        UPDATE t_gds_goods_pic
        SET
              pic_name=#picName#,
              pic_url=#picUrl#,
              modify_emp=#modifyEmp#
        WHERE id = #id#
    </update>

    <!--根据主键id删除图片-->
    <delete id="deleteGoodsPicById" parameterClass="Long">
        DELETE FROM t_gds_goods_pic
        WHERE id = #id#
    </delete>

    <!--根据商品属性id删除图片-->
    <delete id="deleteGoodsPicByPropertyId" parameterClass="Long">
        DELETE FROM t_gds_goods_pic
        WHERE property_id = #propertyId#
    </delete>

    <!--后台通过商品属性id获取商品图片-->
    <select id="getGoodsPicListByPropertyId" parameterClass="Long" resultClass="com.uc.training.smadmin.gds.re.AdminGoodsPicRE">
        SELECT
            ggp.id AS id,
            ggp.pic_name AS picName,
            ggp.pic_url AS picUrl
        FROM   t_gds_goods_pic ggp
        WHERE ggp.property_id = #propertyId#
    </select>

    <!--后台通过图片id获取表中对应商品属性的的数量-->
    <select id="getPropertyIdCountById" parameterClass="Long" resultClass="Integer">
        select count(1)
        from t_gds_goods_pic
        where id = #id#
        group by property_id
    </select>

    <!--后台通过商品属性id查找商品图片的数量-->
    <select id="getCountByGoodsPic" parameterClass="com.uc.training.smadmin.gds.model.GoodsPic" resultClass="Integer">
        select count(1)
        from t_gds_goods_pic
        where 1=1
        <isNotEmpty property="propertyId" prepend="and">
            property_id = #propertyId#
        </isNotEmpty>
    </select>

</sqlMap>